package com.xxd.dfs.namenode;

/**
 * @author: XiaoDong.Xie
 * @create: 2020-08-24 11:02
 * @description: 描述一个datanode
 */
public class DataNodeInfo implements Comparable<DataNodeInfo> {
    private String ip;
    private String hostname;
    private int nioPort;
    /**
     * 最近一次心跳的时间
     */
    private long latestHeartbeatTime;

    /** 已经存储数据的大小 */
    private long storedDataSize;

    public DataNodeInfo(String ip, String hostname, int nioPort) {
        this.ip = ip;
        this.hostname = hostname;
        this.nioPort = nioPort;
    }

    public long getLatestHeartbeatTime() {
        return latestHeartbeatTime;
    }

    public void setLatestHeartbeatTime(long latestHeartbeatTime) {
        this.latestHeartbeatTime = latestHeartbeatTime;
    }

    public String getIp() {
        return ip;
    }

    public void setIp(String ip) {
        this.ip = ip;
    }

    public String getHostname() {
        return hostname;
    }

    public void setHostname(String hostname) {
        this.hostname = hostname;
    }

    public int getNioPort() {
        return nioPort;
    }

    public void setNioPort(int nioPort) {
        this.nioPort = nioPort;
    }

    @Override
    public String toString() {
        return "DataNodeInfo{" +
                "ip='" + ip + '\'' +
                ", hostname='" + hostname + '\'' +
                ", nioPort=" + nioPort +
                ", storedDataSize=" + storedDataSize +
                '}';
    }

    public String getId() {
        return ip + "_" + hostname;
    }


    public long getStoredDataSize() {
        return storedDataSize;
    }

    public void setStoredDataSize(long storedDataSize) {
        this.storedDataSize = storedDataSize;
    }

    @Override
    public int compareTo(DataNodeInfo o) {
        return (int) (this.storedDataSize - o.getStoredDataSize());
    }

    public void addStoredDataSize(long fileSize) {
        this.storedDataSize += storedDataSize;
    }
}
